<script lang="ts" setup>
import { useAdminOrderStore } from '../store/adminOrder'
import { ref } from 'vue'
import { storeToRefs } from 'pinia'
import { post } from '@/utils/api'
import { MessagePlugin } from 'tdesign-vue-next'

const store = useAdminOrderStore()
const { deleteVisible, deleteIds } = storeToRefs(store)
const { getData } = store

const confirmLoading = ref(false)
const confirmDelete = async () => {
  confirmLoading.value = true
  const response = await post('/api/order/softDelete', deleteIds.value)
  MessagePlugin(response.status, response.message)
  if (response.status === 'success') {
    await getData()
  }
  confirmLoading.value = false
  closeDialog()
}

const closeDialog = () => {
  deleteVisible.value = false
  deleteIds.value = []
}
</script>

<template>
  <t-dialog
    :visible="deleteVisible"
    :confirm-btn="{ loading: confirmLoading }"
    @confirm="confirmDelete"
    @close="closeDialog"
    body="删除后可在回收站中恢复，请确认是否要删除？"
    header="警示"
    theme="warning"
  />
</template>

<style lang="less" scoped></style>
